package com.distributer.product.thread;

import java.util.concurrent.ArrayBlockingQueue;

import com.distributer.product.request.Request;

/**
 * 请求处理线程初始化
 * 
 * @author Administrator
 *
 */
public class RequestHanderThreadPoolInit {

	private RequestHanderThreadPoolInit() {
		RequestQueue requestQueue = RequestQueue.getInstance();
		for (int i = 0; i < 10; i++) {
			ArrayBlockingQueue<Request> queue = new ArrayBlockingQueue<Request>(1024);
			Thread requestHanderThread = new Thread(new RequestHanderTask(queue));
			requestHanderThread.setName("RequestHanderThread-" + i);
			requestHanderThread.setDaemon(true);
			requestHanderThread.start();
			requestQueue.add(queue);
		}
	}

	private static class RequestHanderThreadPoolInitInstance {

		private static RequestHanderThreadPoolInit requestHanderThreadPoolInit = null;

		static {
			requestHanderThreadPoolInit = new RequestHanderThreadPoolInit();
		}

		public static RequestHanderThreadPoolInit getInstance() {
			return requestHanderThreadPoolInit;
		}
	}

	public static RequestHanderThreadPoolInit instance() {
		return RequestHanderThreadPoolInitInstance.getInstance();
	}
}
